/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sh.ndt.question.endpoint;

import com.sh.ndt.exception.ServiceException;
import com.sh.ndt.question.entity.Question;
import com.sh.ndt.question.entity.QuestionParam;
import com.sh.ndt.question.service.QuestionService;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author Prashanth
 */
@Controller
@RequestMapping("/questionService")
public class QuestionEndpoint {
    
    private static final Logger LOGGER = Logger.getLogger(QuestionEndpoint.class);
    
    public QuestionEndpoint() {
        LOGGER.debug("QuestionEndpoint is initialized ********************** ");
    }
    
    @Autowired
    QuestionService questionService;
    
    @RequestMapping(value = "/getQuestions",
            method = RequestMethod.POST,
            consumes = "application/xml",
            produces = "application/json"
    )@ResponseBody
    public List<Question> getQuestions(@RequestBody QuestionParam questionParam) {
        try {
            return questionService.getQuestions(questionParam.getCategoryId(),questionParam.getRowLimit());
        } catch (ServiceException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
